package com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.common.entity.SmsImportTask;
import com.xyht.sca_s.student_manage_system.modules.common.entity.SmsImportTaskDetail;
import com.xyht.sca_s.student_manage_system.modules.common.mapper.SmsImportTaskDetailMapper;
import com.xyht.sca_s.student_manage_system.modules.common.mapper.SmsImportTaskMapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementCollegeMajor;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementOrgSetting;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementStudentInfo;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.SmsEnrollmentManagementTask;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementOrgSettingBatchListReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementOrgSettingBatchReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.req.SmsEnrollmentManagementOrgSettingReq;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.entity.resp.SmsEnrollmentManagementOrgSettingResp;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementCollegeMajorMapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementOrgSettingMapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementStudentInfoMapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.mapper.SmsEnrollmentManagementTaskMapper;
import com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.service.SmsEnrollmentManagementOrgSettingService;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskDetailReason.*;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskNameExample.TASK_NAME_COLLEGE_MAJOR_SETTING_IMPORT;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskStatus.TASK_STATUS_DONE;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskStatus.TASK_STATUS_ERR;
import static com.xyht.sca_s.student_manage_system.modules.common.constant.TaskTypeConstant.TASK_TYPE_COLLEGE_MAJOR_SETTING;
import static com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.constant.OrgTypeConstant.ORG_TYPE_COLLEGE;
import static com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.constant.OrgTypeConstant.ORG_TYPE_MAJOR;
import static com.xyht.sca_s.student_manage_system.modules.enrollmentManagement.constant.TaskStatusConstant.TASK_STATUS_OPEN;

/**
 * <p>
 * 招生院系专业组织架构设置 服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2024-01-24
 */
@Service
public class SmsEnrollmentManagementOrgSettingServiceImpl extends ServiceImpl<SmsEnrollmentManagementOrgSettingMapper, SmsEnrollmentManagementOrgSetting> implements SmsEnrollmentManagementOrgSettingService {
    @Resource
    private SmsEnrollmentManagementOrgSettingMapper smsEnrollmentManagementOrgSettingMapper;
    @Resource
    private SmsEnrollmentManagementStudentInfoMapper smsEnrollmentManagementStudentInfoMapper;
    @Resource
    private SmsEnrollmentManagementCollegeMajorMapper smsEnrollmentManagementCollegeMajorMapper;
    @Resource
    private SmsEnrollmentManagementTaskMapper smsEnrollmentManagementTaskMapper;
    @Resource
    private SmsImportTaskMapper smsImportTaskMapper;
    @Resource
    private PlatformTransactionManager transactionManager;
    @Resource
    private SmsImportTaskDetailMapper smsImportTaskDetailMapper;


    @Override
    public ResponseResult addEnrollmentOrgSetting(SmsEnrollmentManagementOrgSettingReq settingReq) {
        if (isNullOrEmpty(settingReq.getOrgType(), settingReq.getOrgName(),
                settingReq.getParentId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        if (!settingReq.getOrgType().equals(ORG_TYPE_COLLEGE) && !settingReq.getOrgType().equals(ORG_TYPE_MAJOR)) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        if (settingReq.getOrgType().equals(ORG_TYPE_MAJOR)) {
            SmsEnrollmentManagementOrgSetting orgSetting = smsEnrollmentManagementOrgSettingMapper.selectById(settingReq.getParentId());
            if (orgSetting == null) {
                return CommonResult.failed(CommonCodeEnum.ORG_NOT_EXIST);
            }
            if (!orgSetting.getOrgType().equals(ORG_TYPE_COLLEGE)) {
                return CommonResult.failed(CommonCodeEnum.ORG_PARENT_TYPE_ERR);
            }
        }

        List<SmsEnrollmentManagementOrgSetting> orgSettingList = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                .and(wrapper -> {
                    wrapper.eq(SmsEnrollmentManagementOrgSetting::getOrgName, settingReq.getOrgName())
                            .or()
                            .eq(SmsEnrollmentManagementOrgSetting::getOrgCode, settingReq.getOrgCode());
                }));
        if (orgSettingList != null && orgSettingList.size() > 0) {
            return CommonResult.failed(CommonCodeEnum.ORG_NAME_OR_CODE_EXIST);
        }

        SmsEnrollmentManagementOrgSetting addSetting = new SmsEnrollmentManagementOrgSetting();
        addSetting.setOrgType(settingReq.getOrgType());
        addSetting.setOrgName(settingReq.getOrgName());
        addSetting.setOrgCode(settingReq.getOrgCode());
        if (settingReq.getOrgType().equals(ORG_TYPE_COLLEGE)) {
            addSetting.setParentId("0");
        } else if (settingReq.getOrgType().equals(ORG_TYPE_MAJOR)) {
            addSetting.setParentId(settingReq.getParentId());
        }
        smsEnrollmentManagementOrgSettingMapper.insert(addSetting);
        return CommonResult.success();
    }

    @Override
    public ResponseResult deleteEnrollmentOrgSetting(SmsEnrollmentManagementOrgSettingReq settingReq) {
        if (isNullOrEmpty(settingReq.getId())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        SmsEnrollmentManagementOrgSetting orgSetting = smsEnrollmentManagementOrgSettingMapper.selectById(settingReq.getId());
        if (orgSetting == null) {
            return CommonResult.failed(CommonCodeEnum.ORGANIZATION_NOT_EXIST);
        }

        if (orgSetting.getOrgType().equals(ORG_TYPE_COLLEGE)) {
            List<SmsEnrollmentManagementOrgSetting> childOrgList = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                    .eq(SmsEnrollmentManagementOrgSetting::getParentId, settingReq.getId()));
            if (childOrgList != null && childOrgList.size() > 0) {
                return CommonResult.failed(CommonCodeEnum.ORG_CHILD_EXIST);
            }
        }

        smsEnrollmentManagementOrgSettingMapper.deleteById(settingReq.getId());
        return CommonResult.success();
    }

    @Override
    @Transactional
    public ResponseResult updateEnrollmentOrgSetting(SmsEnrollmentManagementOrgSettingReq settingReq) {
        if (isNullOrEmpty(settingReq.getId(), settingReq.getOrgName())) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        SmsEnrollmentManagementOrgSetting orgSetting = smsEnrollmentManagementOrgSettingMapper.selectById(settingReq.getId());
        if (orgSetting == null) {
            return CommonResult.failed(CommonCodeEnum.ORGANIZATION_NOT_EXIST);
        }

        SmsEnrollmentManagementOrgSetting updateOrgSetting = new SmsEnrollmentManagementOrgSetting();
        updateOrgSetting.setId(settingReq.getId());
        updateOrgSetting.setOrgName(settingReq.getOrgName());
        updateOrgSetting.setOrgCode(settingReq.getOrgCode());
        smsEnrollmentManagementOrgSettingMapper.updateById(updateOrgSetting);

        if (!settingReq.getOrgName().equals(orgSetting.getOrgName())) {
            //修改学院专业计划表
            SmsEnrollmentManagementCollegeMajor updateCollegeMajor = new SmsEnrollmentManagementCollegeMajor();
            LambdaQueryWrapper<SmsEnrollmentManagementCollegeMajor> collegeMajorQueryWrapper = new LambdaQueryWrapper<>();
            if (orgSetting.getOrgType().equals(ORG_TYPE_COLLEGE)) {
                updateCollegeMajor.setCollegeName(settingReq.getOrgName());

                collegeMajorQueryWrapper.eq(SmsEnrollmentManagementCollegeMajor::getCollegeId, settingReq.getId());
            } else {
                updateCollegeMajor.setMajorName(settingReq.getOrgName());

                collegeMajorQueryWrapper.eq(SmsEnrollmentManagementCollegeMajor::getMajorId, settingReq.getId());
            }
            smsEnrollmentManagementCollegeMajorMapper.update(updateCollegeMajor, collegeMajorQueryWrapper);

            //修改招生信息学生表
            SmsEnrollmentManagementStudentInfo updateStudentInfo = new SmsEnrollmentManagementStudentInfo();
            LambdaQueryWrapper<SmsEnrollmentManagementStudentInfo> studentInfoQueryWrapper = new LambdaQueryWrapper<>();
            if (orgSetting.getOrgType().equals(ORG_TYPE_COLLEGE)) {
                updateStudentInfo.setCollegeName(settingReq.getOrgName());

                studentInfoQueryWrapper.eq(SmsEnrollmentManagementStudentInfo::getCollegeId, settingReq.getId());
            } else {
                updateStudentInfo.setMajorName(settingReq.getOrgName());

                studentInfoQueryWrapper.eq(SmsEnrollmentManagementStudentInfo::getMajorId, settingReq.getId());
            }
            smsEnrollmentManagementStudentInfoMapper.update(updateStudentInfo, studentInfoQueryWrapper);
        }
        return CommonResult.success();
    }

    @Override
    public ResponseResult getEnrollmentOrgSettingList(Integer orgType, String parentId, String searchStr, Integer pageNum, Integer pageSize) {
        QueryWrapper<SmsEnrollmentManagementOrgSetting> queryWrapper = new QueryWrapper<>();
        if (!isNullOrEmpty(orgType)) {
            queryWrapper.lambda().eq(SmsEnrollmentManagementOrgSetting::getOrgType, orgType);
        }
        if (orgType.equals(ORG_TYPE_MAJOR)) {
            if (!isNullOrEmpty(parentId)) {
                queryWrapper.lambda().eq(SmsEnrollmentManagementOrgSetting::getParentId, parentId);
            }
        }
        if (!isNullOrEmpty(searchStr)) {
            queryWrapper.lambda().and(wrapper -> {
                wrapper.like(SmsEnrollmentManagementOrgSetting::getOrgName, searchStr)
                        .or()
                        .like(SmsEnrollmentManagementOrgSetting::getOrgCode, searchStr);
            });
        }
        Page<SmsEnrollmentManagementOrgSetting> page = new Page<>(pageNum, pageSize);
        smsEnrollmentManagementOrgSettingMapper.selectPage(page, queryWrapper);
        List<SmsEnrollmentManagementOrgSettingResp> list = page.getRecords()
                .stream()
                .map(orgSetting -> {
                    SmsEnrollmentManagementOrgSettingResp orgSettingResp = new SmsEnrollmentManagementOrgSettingResp();
                    BeanUtils.copyProperties(orgSetting, orgSettingResp);
                    return orgSettingResp;
                })
                .collect(Collectors.toList());
        int total = (int) page.getTotal();
        return CommonResult.success(list, total);
    }

    @Override
    public ResponseResult getEnrollmentOrgCollegeAndMajorStudentDisplay(Integer orgType, String parentId) {
        List<SmsEnrollmentManagementOrgSettingResp> list = new ArrayList<>();
        if (orgType.equals(ORG_TYPE_MAJOR)) {
            if (isNullOrEmpty(parentId)) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }
        }

        SmsEnrollmentManagementTask task = smsEnrollmentManagementTaskMapper.selectOne(new LambdaQueryWrapper<SmsEnrollmentManagementTask>()
                .eq(SmsEnrollmentManagementTask::getTaskStatus, TASK_STATUS_OPEN));
        if (task == null) {
            return CommonResult.failed(CommonCodeEnum.ENROLLMENT_MANAGEMENT_TASK_NOT_OPEN);
        }

        QueryWrapper<SmsEnrollmentManagementCollegeMajor> collegeMajorQueryWrapper = new QueryWrapper<>();
        collegeMajorQueryWrapper.lambda().eq(SmsEnrollmentManagementCollegeMajor::getTaskId, task.getId());
        if (orgType.equals(ORG_TYPE_COLLEGE)) {
            collegeMajorQueryWrapper.select("college_id")
                    .lambda()
                    .groupBy(SmsEnrollmentManagementCollegeMajor::getCollegeId);
        } else {
            collegeMajorQueryWrapper.select("major_id")
                    .lambda().eq(SmsEnrollmentManagementCollegeMajor::getCollegeId, parentId)
                    .groupBy(SmsEnrollmentManagementCollegeMajor::getMajorId);
        }
        List<SmsEnrollmentManagementCollegeMajor> collegeMajorList = smsEnrollmentManagementCollegeMajorMapper.selectList(collegeMajorQueryWrapper);
        if (collegeMajorList == null || collegeMajorList.size() < 1) {
            return CommonResult.success(list);
        }

        List<String> orgIdList;
        if (orgType.equals(ORG_TYPE_COLLEGE)) {
            orgIdList = collegeMajorList.stream().map(SmsEnrollmentManagementCollegeMajor::getCollegeId).collect(Collectors.toList());
        } else {
            orgIdList = collegeMajorList.stream().map(SmsEnrollmentManagementCollegeMajor::getMajorId).collect(Collectors.toList());
        }

        LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SmsEnrollmentManagementOrgSetting::getId, orgIdList)
                .orderByAsc(SmsEnrollmentManagementOrgSetting::getOrgCode);
        list = smsEnrollmentManagementOrgSettingMapper.selectList(queryWrapper)
                .stream()
                .map(orgSetting -> {
                    SmsEnrollmentManagementOrgSettingResp orgSettingResp = new SmsEnrollmentManagementOrgSettingResp();
                    BeanUtils.copyProperties(orgSetting, orgSettingResp);
                    return orgSettingResp;
                })
                .collect(Collectors.toList());
        return CommonResult.success(list);
    }

    @Override
    public ResponseResult getEnrollmentOrgCollegeAndMajorBackDisplay(Integer orgType, String parentId) {
        if (orgType.equals(ORG_TYPE_MAJOR)) {
            if (isNullOrEmpty(parentId)) {
                return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
            }
        }

        LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SmsEnrollmentManagementOrgSetting::getOrgType, orgType);
        if (orgType.equals(ORG_TYPE_COLLEGE)) {
            queryWrapper.eq(SmsEnrollmentManagementOrgSetting::getParentId, "0");
        } else {
            queryWrapper.eq(SmsEnrollmentManagementOrgSetting::getParentId, parentId);
        }
        queryWrapper.orderByAsc(SmsEnrollmentManagementOrgSetting::getOrgCode);
        List<SmsEnrollmentManagementOrgSettingResp> list = smsEnrollmentManagementOrgSettingMapper.selectList(queryWrapper)
                .stream()
                .map(orgSetting -> {
                    SmsEnrollmentManagementOrgSettingResp orgSettingResp = new SmsEnrollmentManagementOrgSettingResp();
                    BeanUtils.copyProperties(orgSetting, orgSettingResp);
                    return orgSettingResp;
                })
                .collect(Collectors.toList());
        return CommonResult.success(list);
    }

    @Override
    public Future<ResponseResult> batchEnrollmentManagementCollegeMajorSetting(SmsEnrollmentManagementOrgSettingBatchReq orgSettingBatchReq, String user_id) {
        if (orgSettingBatchReq.getOrgSettingList() == null || orgSettingBatchReq.getOrgSettingList().size() < 1) {
            return new AsyncResult<>(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        //创建导入任务
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setTaskName(TASK_NAME_COLLEGE_MAJOR_SETTING_IMPORT);
        smsImportTask.setUserId(user_id);
        smsImportTask.setTaskType(TASK_TYPE_COLLEGE_MAJOR_SETTING);
        smsImportTaskMapper.insert(smsImportTask);
        batchAddEnrolCollegeMajorSetting(orgSettingBatchReq, smsImportTask.getId());
        return new AsyncResult<>(CommonResult.success());
    }

    private void batchAddEnrolCollegeMajorSetting(SmsEnrollmentManagementOrgSettingBatchReq orgSettingBatchReq, String task_id) {
        int OFFSET_ROW = 2;
        int task_status = TASK_STATUS_DONE;
        for (int i = 0; i < orgSettingBatchReq.getOrgSettingList().size(); i++) {
            //开启事务
            DefaultTransactionDefinition dt = new DefaultTransactionDefinition();
            // 嵌套事务 PROPAGATION_REQUIRES_NEW 每次开启一个新的事务
            dt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
            // 设置嵌套事务
            TransactionStatus status = transactionManager.getTransaction(dt);
            try {
                SmsEnrollmentManagementOrgSettingBatchListReq orgSettingBatchListReq = orgSettingBatchReq.getOrgSettingList().get(i);
                if (isNullOrEmpty(orgSettingBatchListReq.getMajorName(), orgSettingBatchListReq.getCollegeName())) {
                    transactionManager.rollback(status);
                    task_status = TASK_STATUS_ERR;
                    createTeacherImportTaskDetail(task_id, REASON_INVALID_PARAM, (i + OFFSET_ROW) + "");
                    continue;
                }

                //判断院系专业是否已经设置过
                //设置过跳过  没设置过就添加
                //获取院系id和院系名
                String collegeId;
                List<SmsEnrollmentManagementOrgSetting> collegeList = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                        .eq(SmsEnrollmentManagementOrgSetting::getOrgName, orgSettingBatchListReq.getCollegeName()));
                if (collegeList == null || collegeList.size() < 1) {
                    //添加院系
                    SmsEnrollmentManagementOrgSetting addCollege = new SmsEnrollmentManagementOrgSetting();
                    addCollege.setParentId("0");
                    addCollege.setOrgType(ORG_TYPE_COLLEGE);
                    addCollege.setOrgName(orgSettingBatchListReq.getCollegeName());
                    smsEnrollmentManagementOrgSettingMapper.insert(addCollege);

                    collegeId = addCollege.getId();
                } else {
                    SmsEnrollmentManagementOrgSetting college = collegeList.get(0);
                    if (college.getOrgType().equals(ORG_TYPE_MAJOR)){
                        transactionManager.rollback(status);
                        task_status = TASK_STATUS_ERR;
                        createTeacherImportTaskDetail(task_id, REASON_ENROLLMENT_ORG_COLLEGE_REPEAT_MAJOR, (i + OFFSET_ROW) + "");
                        continue;
                    }
                    collegeId = collegeList.get(0).getId();
                }


                List<SmsEnrollmentManagementOrgSetting> majorList = smsEnrollmentManagementOrgSettingMapper.selectList(new LambdaQueryWrapper<SmsEnrollmentManagementOrgSetting>()
                        .eq(SmsEnrollmentManagementOrgSetting::getOrgName, orgSettingBatchListReq.getMajorName()));
                if (majorList == null || majorList.size() < 1) {
                    //添加专业
                    SmsEnrollmentManagementOrgSetting addMajor = new SmsEnrollmentManagementOrgSetting();
                    addMajor.setParentId(collegeId);
                    addMajor.setOrgType(ORG_TYPE_MAJOR);
                    addMajor.setOrgName(orgSettingBatchListReq.getMajorName());
                    addMajor.setOrgCode(orgSettingBatchListReq.getMajorCode());
                    smsEnrollmentManagementOrgSettingMapper.insert(addMajor);
                }else{
                    SmsEnrollmentManagementOrgSetting major = majorList.get(0);
                    if (major.getOrgType().equals(ORG_TYPE_COLLEGE)){
                        transactionManager.rollback(status);
                        task_status = TASK_STATUS_ERR;
                        createTeacherImportTaskDetail(task_id, REASON_ENROLLMENT_ORG_MAJOR_REPEAT_COLLEGE, (i + OFFSET_ROW) + "");
                        continue;
                    }

                    if (!major.getParentId().equals(collegeId)){
                        transactionManager.rollback(status);
                        task_status = TASK_STATUS_ERR;
                        createTeacherImportTaskDetail(task_id, REASON_ENROLLMENT_ORG_MAJOR_EXIST_OTHER_COLLEGE, (i + OFFSET_ROW) + "");
                        continue;
                    }

                }

                transactionManager.commit(status);
            } catch (Exception e) {
                transactionManager.rollback(status);
                task_status = TASK_STATUS_ERR;
                createTeacherImportTaskDetail(task_id, REASON_IMPORT_ERR, (i + OFFSET_ROW) + "");
            } finally {
                if (status.isNewTransaction() && !status.isCompleted()) {
                    transactionManager.commit(status);
                }
            }
        }
        SmsImportTask smsImportTask = new SmsImportTask();
        smsImportTask.setId(task_id);
        smsImportTask.setStatus(task_status);
        smsImportTaskMapper.updateById(smsImportTask);
    }

    private void createTeacherImportTaskDetail(String task_id, String reason, String row) {
        SmsImportTaskDetail smsImportTaskDetail = new SmsImportTaskDetail();
        smsImportTaskDetail.setTaskId(task_id);
        smsImportTaskDetail.setFailReason(reason);
//        smsImportTaskDetail.setFailName(name);
        smsImportTaskDetail.setFailRow(row);
        smsImportTaskDetailMapper.insert(smsImportTaskDetail);
    }
}
